package library.frames.model;

import java.util.LinkedList;
import java.util.List;
import javax.swing.table.DefaultTableModel;
import library.download.Download;

public class DownloadTableModel extends DefaultTableModel {

    private List<Download> downloads = new LinkedList<Download>();
    private static String[] columnNames = {"Название", "Статус"};

    @Override
    public boolean isCellEditable(int row, int column) {
        return false;
    }

    @Override
    public int getRowCount() {
        if (downloads == null) {
            return 0;

        }
        return downloads.size();
    }

    @Override
    public String getColumnName(int column) {
        return columnNames[column];
    }

    @Override
    public int getColumnCount() {
        return columnNames.length;
    }

    @Override
    public Object getValueAt(int row, int column) {
        Download download = downloads.get(row);
        switch (column) {
            case 0:
                return download.getName();
            case 1:
                return download.getState();
        }
        return null;
    }

    public void addDownload(Download d) {
        this.downloads.add(d);
    }
}
